﻿@model Himall.Web.Areas.SellerAdmin.Models.ShopProfileStep2
<link rel="stylesheet" type="text/css" href="~/Content/bootstrap-datetimepicker.min.css">
<div class="container">
    <ul class="nav nav-tabs-custom clearfix">
		<li class="active"><a>财务信息</a></li>
        <div class="process-step">
            <span class="odd">公司信息</span>
            <i class="glyphicon glyphicon-arrow-right odd"></i>
            <span class="odd">财务信息</span>
            <i class="glyphicon glyphicon-arrow-right"></i>
            <span>店铺信息</span>
            <i class="glyphicon glyphicon-arrow-right"></i>
            <span>审核状态</span>
        </div>
    </ul>
    <form id="form_step2" class="form-horizontal form-pt0" role="form">
    <h3 class="table-hd">开户银行信息</h3>
    <div class="form-group">
        <label for="" class="col-sm-2 control-label"><b>*</b>银行开户名：</label>
        <div class="col-sm-3">
            @Html.TextBoxFor(item => item.BankAccountName, new { @class = "form-control input-sm" })
        </div>
        <div class="col-sm-3">
            @Html.ValidationMessageFor(item => item.BankAccountName)
        </div>
    </div>
    <div class="form-group">
        <label for="" class="col-sm-2 control-label"><b>*</b>公司银行账号：</label>
        <div class="col-sm-3">
            @Html.TextBoxFor(item => item.BankAccountNumber, new { @class = "form-control input-sm" })
        </div>
        <div class="col-sm-3">
            @Html.ValidationMessageFor(item => item.BankAccountNumber)
        </div>
    </div>
    <div class="form-group">
        <label for="" class="col-sm-2 control-label"><b>*</b>开户银行支行名称：</label>
        <div class="col-sm-3">
            @Html.TextBoxFor(item => item.BankName, new { @class = "form-control input-sm" })
        </div>
        <div class="col-sm-3">
            @Html.ValidationMessageFor(item => item.BankName)
        </div>
    </div>
    <div class="form-group">
        <label for="" class="col-sm-2 control-label"><b>*</b>支行联行号：</label>
        <div class="col-sm-3">
            @Html.TextBoxFor(item => item.BankCode, new { @class = "form-control input-sm" })
        </div>
        <div class="col-sm-3">
            @Html.ValidationMessageFor(item => item.BankCode)
        </div>
    </div>
    <div class="form-group">
        <label for="" class="col-sm-2 control-label"><b>*</b>开户银行所在地：</label>
        <div class="col-sm-5">
            <select id="bankLocationProvince" class="form-control input-sm select-sort"></select>
            <select id="bankLocationCity" class="form-control input-sm select-sort"></select>
            <select id="bankLocationDistrict" class="form-control input-sm select-sort"></select>
        </div>
        <div class="col-sm-3">
            @Html.ValidationMessageFor(item => item.BankRegionId)
        </div>
            @Html.TextBoxFor(item => item.BankRegionId, new { style = "width:0px;height:0px; border-width:0px;" })
    </div>
    <div class="form-group upload-img" id="bankPhoto"></div>

    <h3 class="table-hd">税务登记证</h3>
    <div class="form-group">
        <label for="" class="col-sm-2 control-label"><b>*</b>税务登记证号：</label>
        <div class="col-sm-3">
            @Html.TextBoxFor(item => item.TaxRegistrationCertificate, new { @class = "form-control input-sm" })
        </div>
        <div class="col-sm-3">
            @Html.ValidationMessageFor(item => item.TaxRegistrationCertificate)
        </div>
    </div>
    <div class="form-group">
        <label for="" class="col-sm-2 control-label"><b>*</b>纳税人识别号：</label>
        <div class="col-sm-3">
            @Html.TextBoxFor(item => item.TaxpayerId, new { @class = "form-control input-sm" })
        </div>
        <div class="col-sm-3">
            @Html.ValidationMessageFor(item => item.TaxpayerId)
        </div>
    </div>
    <div class="form-group upload-img " id="taxRegistrationCertificatePhoto"></div>

    <div class="form-group">
        <div class="col-sm-offset-2 col-sm-10">
            <a id="submit" class="btn btn-primary" href="javascript:;">下 一 步</a>
            &nbsp;&nbsp;&nbsp;&nbsp;
            <a id="backpre" class="btn btn-back" href="@(Url.Action("EditProfile1"))" target="_top">返回上一步</a>
        </div>
    </div>
</form>
</div>
<script src="~/Scripts/Region.js"></script>
<script src="~/Scripts/jquery.himallUpload.js"></script>
<script src="~/Scripts/jquery.himallLinkage.nocreate.js"></script>
<script>
    $(function () {
        $('#bankLocationProvince,#bankLocationCity,#bankLocationDistrict').himallLinkage({//开户银行所在地
            url: '/common/RegionAPI/GetRegion',
            enableDefaultItem: true,
            defaultItemsText: '请选择',
            defaultSelectedValues: [@ViewBag.BankRegionIds],
            onChange: function (level, value, text) {
                var len = $("#bankLocationDistrict option").size();
                if (level == 1 && len == 0)
                {
                    $("#BankRegionId").val(value);
                }
                else if (level == 2)
                    $("#BankRegionId").val(value);
            }
        });

        $('#submit').click(function () {
            var form = $('#form_step2');
            if (form.valid()) {


                var bankPhoto = $('#bankPhoto').himallUpload('getImgSrc');
                var taxRegistrationCertificatePhoto = $('#taxRegistrationCertificatePhoto').himallUpload('getImgSrc');
                if (!isSelectAddr($('#bankLocationProvince'), $('#bankLocationCity'), $('#bankLocationDistrict')))
                    $.dialog.errorTips('请选择开户银行所在地');
                else if (!bankPhoto)
                    $.dialog.errorTips('请上传开户银行许可证电子版');
                else if (!taxRegistrationCertificatePhoto)
                    $.dialog.errorTips('请上传税务登记证号电子版');
                else {
                    var data = form.serialize();
                    var loading = showLoading();
                    $.post('EditProfile2', data, function (result) {
                        loading.close();
                        if (result.success)
                            window.top.location.href = "@(Url.Action("EditProfile3"))";
                        else
                            alert(result.success);
                    });
                }
            }
        });


        $('#bankPhoto').himallUpload({
            title: '<b>*</b>开户银行许可证电子版：',
            imageDescript: '请确保图片清晰，文字可辨并有清晰的红色公章。',
            displayImgSrc: '@Model.BankPhoto',
            imgFieldName: "bankPhoto",
            dataWidth: 6
        });


        $('#taxRegistrationCertificatePhoto').himallUpload({
            title: '<b>*</b>税务登记证号电子版：',
            imageDescript: '请确保图片清晰，文字可辨并有清晰的红色公章。',
            displayImgSrc: '@Model.TaxRegistrationCertificatePhoto',
            imgFieldName: "taxRegistrationCertificatePhoto",
            dataWidth: 6
        });

    });

    function bindCity(provinceControl, cityControl, countyControl, regionId) {
        var regions = regionId.split(',');
        var shengfen = regions.length > 0 ? regions[0] : 0;
        var city = regions.length > 1 ? regions[1] : 0;
        var county = regions.length > 2 ? regions[2] : 0;
        $('#' + provinceControl + ',#' + cityControl + ',#' + countyControl).cityLink(shengfen, city, county);
        $('#' + cityControl).removeAttr('disabled');
        $('#' + countyControl).removeAttr('disabled');
    }



    var isSelectAddr = function (p, c, t) {
        if (!p || !c || !t)
            return false;
        var haveProvince = false;
        var haveCity = false;
        var haveTown = false;
        p.children().each(function (i, e) {
            s = e.selected;
            if (s == true && i > 0) {
                haveProvince = true;
                return;
            }
        });
        if (haveProvince) {
            c.children().each(function (i, e) {
                s = e.selected;
                v = e.value;
                if (s == true && v != "") {
                    haveCity = true;
                    return;
                }
            });
            if (haveCity) {
                var idx = 0;
                t.children().each(function (i, e) {
                    s = e.selected;
                    v = e.value;
                    idx = i;
                    if (s == true && v != "") {
                        haveTown = true;
                        return;
                    }
                });
                haveTown = idx > 0 ? haveTown : true;
            }
        }
        return haveProvince && haveCity && haveTown;
    };
</script>
<script src="~/Scripts/jquery.validate.js"></script>
<script src="~/Scripts/jquery.validate.unobtrusive.js"></script>
